package com.eat.fish_service.config.quartzConfig;

import com.eat.fish_service.utils.GetBeanUtils;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Component;

/**
 * @author CZF
 * @create 2022-05-12 17:14
 */
public class TriggerUtils {

    //返回自定义Trigger
    public Trigger getTrigger(Scheduler scheduler, String name, String group) {
        Trigger trigger = null;

        try {

            TriggerKey triggerKey = TriggerKey.triggerKey("senorDataTrigger", "group1");
            //调度器根据triggerkey生成trigger
            trigger = scheduler.getTrigger(triggerKey);
            if (trigger == null) {
                //配置trigger(触发器)
                trigger = TriggerBuilder.newTrigger()
                        .withIdentity(triggerKey)
                        .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInMinutes(10))//10分钟执行一次，从鱼缸中获取水质数据
                        .startNow()
                        .build();
            }

        } catch (SchedulerException e) {
            e.printStackTrace();
            return null;
        }
        return trigger;
    }

    //返回自定义JobDetail
}
